package com.gk.javaservice.controller;

import com.gk.javaservice.common.ServerResponse;
import com.gk.javaservice.po.AdminRolePermissions;
import com.gk.javaservice.service.AdminRolePermissionsService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/AdminRolePermissions")
public class AdminRolePermissionsController {

    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private AdminRolePermissionsService adminRoleMenuService;

    //添加终端
    @CrossOrigin
    @ResponseBody
    @RequestMapping("/add")
    public ServerResponse<?> add(@RequestBody AdminRolePermissions t) {

        try {
            adminRoleMenuService.add(t);
            return ServerResponse.createBySuccess(t);
        } catch (Exception e) {
            return ServerResponse.createByErrorMessage("值重复");
        }


    }

    //根据ID删除1个终端
    @CrossOrigin
    @ResponseBody
    @RequestMapping("/delete")
    public ServerResponse<?> del(@RequestBody AdminRolePermissions t) {

        log.info(t);
        adminRoleMenuService.delete(t);
        return ServerResponse.createBySuccess();

    }

    //修改终端信息
    @CrossOrigin
    @ResponseBody
    @RequestMapping("/update")
    public ServerResponse<?> update(@RequestBody AdminRolePermissions t) {


        adminRoleMenuService.update(t);
        return ServerResponse.createBySuccess(t);

    }

    //获取所有终端信息
    @CrossOrigin
    @ResponseBody
    @RequestMapping("/hasAll")
    public ServerResponse<?> hasAll() {


        return ServerResponse.createBySuccess(adminRoleMenuService.hasAll());

    }

    //根据ID获取终端信息
    @CrossOrigin
    @ResponseBody
    @RequestMapping("/hasById")
    public ServerResponse<?> hasById(HttpServletRequest request) {
        String id = request.getParameter("id");
        log.info("id:" + id);
        return ServerResponse.createBySuccess(adminRoleMenuService.hasById(id));

    }

    //根据ID获取终端信息
    @CrossOrigin
    @ResponseBody
    @RequestMapping("/hasAllById")
    public ServerResponse<?> hasAllById(HttpServletRequest request) {
        String id = request.getParameter("id");
        log.info("id:" + id);
        return ServerResponse.createBySuccess(adminRoleMenuService.hasAllById(id));

    }

}
